<?php

require_once 'Tavs/Mail/Loader.php';

abstract class Tavs_Mail_Loader_Abstract extends Tavs_Mail_Loader
{
	/**
	 * Values to be assign in the template
	 *
	 * @var array
	 */
	protected $_vars = array();

	/**
	 * Content of template
	 *
	 * @var string
	 */
	protected $_content;

	/**
	 * Assign var or vars in $_vars
	 *
	 * @param string|array $name
	 * @param mixed $value
	 *
	 * @return Tavs_Mail_Loader_Abstract
	 */
	public function assign($name, $value = null)
	{
		if (is_array($name)) {
			foreach ($name as $key => $val) {
				$this->assign($key, $val);
			}
		}
		else {
			$name = (string) $name;
			$this->_vars[$name] = $value;
		}

		return $this;
	}

	/**
	 * Shortcut for assign()
	 *
	 * @param string $name
	 * @param mixed $value
	 */
	public function __set($name, $value)
	{
		$this->assign($name, $value);
	}

	public function send($transport = null)
	{
		$content = $this->_render();

		$this
			->setBodyHtml($content)
			->setBodyText($content);

		return parent::send($transport);
	}

	abstract protected function _render();
}